home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PP_v1.4 / Source / fragalloc.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  1KB  |  61 lines

  1. /* FragAlloc - "end-to-end fragments" allocation and deallocation functions
  2. **
  3. ** These two functions are used by Powerpacker Patcher V1.4. They allocate/
  4. ** deallocate a block of memory by splitting it up into consequitive,
  5. ** smaller blocks.
  6. **
  7. ** This file belongs to the Powerpacker Patcher project.
  8. **
  9. ** Copyright 1991, Michael Berg
  10. */
  11.  
  12. #include <pragmas.h>
  13. #include <exec/types.h>
  14.  
  15. UBYTE *fragallocabs(int size,register chsize,UBYTE *where)
  16. {
  17.     register UBYTE *memgot;
  18.  
  19.     if (memgot = AllocAbs(size,where))
  20.     {
  21.         register nchunks;
  22.         register i;
  23.         int lchunk;
  24.  
  25.         nchunks = size / chsize;
  26.         lchunk  = size % chsize;
  27.  
  28.         Forbid();
  29.  
  30.         FreeMem(memgot,size);
  31.  
  32.         for (i=0; i<nchunks; i++)
  33.             AllocAbs(chsize,memgot + i*chsize);
  34.  
  35.         if (lchunk)
  36.             AllocAbs(lchunk,memgot + i*chsize);
  37.  
  38.         Permit();
  39.     }
  40.  
  41.     return(memgot);
  42. }
  43.  
  44. void fragfree(register UBYTE *memgot,int size, register chsize)
  45. {
  46.     register nchunks;
  47.     int lchunk;
  48.  
  49.     nchunks = size / chsize;
  50.     lchunk  = size % chsize;
  51.  
  52.     while (nchunks--)
  53.     {
  54.         FreeMem(memgot,chsize);
  55.         memgot += chsize;
  56.     }
  57.  
  58.     if (lchunk)
  59.         FreeMem(memgot,lchunk);
  60. }
  61.